// 获取UP主信息
function displayUpInfo(info) {
  const nameElement = document.getElementById('upName');
  const descElement = document.getElementById('upDescription');
  const followersElement = document.getElementById('upFollowers');
  
  if (!info) {
    nameElement.textContent = '加载中...';
    descElement.textContent = '正在获取UP主信息';
    followersElement.textContent = '-';
    return;
  }
  
  nameElement.textContent = info.name || '未知UP主';
  descElement.textContent = info.description || '暂无简介';
  followersElement.textContent = info.followers || '未知';
}

// 标签切换功能
document.getElementById('videoTab').addEventListener('click', () => {
  window.location.href = 'popup.html';
});

document.getElementById('upTab').addEventListener('click', () => {
  // 已经在UP主页面，无需操作
});

// 初始显示加载状态
document.addEventListener('DOMContentLoaded', () => {
  displayUpInfo(null);
});

// 当页面打开时，尝试获取数据
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
  const currentTab = tabs[0];
  if (currentTab && currentTab.url && currentTab.url.includes('bilibili.com/video')) {
    chrome.tabs.sendMessage(currentTab.id, {type: 'GET_UP_INFO'});
  } else {
    displayUpInfo({
      name: '请在B站视频页面使用此扩展',
      description: ''
    });
  }
});

// 监听来自content script的消息
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  console.log('收到UP主信息:', message);
  if (message.type === 'UP_INFO') {
    displayUpInfo(message.data);
  }
}); 